home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 176-200 / scopedisk180 / patch / amystat.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  2KB  |  82 lines

  1. /* this is an implementation of the Unix "stat" library routine
  2.    for the Amiga computer and Lattice compiler.
  3.    November '89 Eric Green.
  4. */
  5.  
  6. #include "stat.h"
  7.  
  8. #include <libraries/dos.h>
  9. #include <libraries/dosextens.h>
  10.  
  11. #ifdef LATTICE
  12. #include <proto/dos.h>
  13. #else
  14.   struct FileLock *Lock();
  15.   long Examine();
  16.   void UnLock();
  17. #endif
  18.  
  19. #include <exec/memory.h>
  20.  
  21. #ifdef LATTICE
  22. #include <proto/exec.h>
  23. #else
  24.   struct FileInfoBlock *AllocMem();
  25.   void FreeMem();
  26. #endif
  27.  
  28. #include <errno.h>
  29.  
  30. #ifdef LATTICE
  31. #include <dos.h>   /* for getft() */
  32. #endif
  33.  
  34. int stat(name,buf)
  35.   char *name;
  36.   register struct stat *buf;
  37. {
  38.     register struct FileLock *f;
  39.     register struct FileInfoBlock *fib;
  40.     register long result;
  41.  
  42.     f = Lock(name,SHARED_LOCK);
  43.     if (f==0) {
  44.         /* return an io error. */
  45.         errno = ENOENT;  /* doesn't exist. */
  46.         return -1;
  47.     }
  48.  
  49.     fib = AllocMem(sizeof(struct FileInfoBlock),MEMF_CLEAR|MEMF_PUBLIC);
  50.     result = Examine(f,fib);
  51. /* result might be nothing -- in which case our FIB is blank. If so,
  52.    well, what more can we do here? Why are they Examine()'ing a
  53.    SER: device anyhow?
  54. */
  55.  
  56.     UnLock(f);  /* clean up that, at least. */
  57.  
  58.     buf->st_rdev = buf->st_dev = DeviceProc(name);
  59.     buf->st_ino = fib->fib_DiskKey;  /* AmigaDOS equivalent. */
  60.  
  61.     buf->st_mode = (fib->fib_DirEntryType > 0) ? S_IFDIR : S_IFREG;
  62.  
  63.     if (fib->fib_Protection & FIBF_READ)
  64.         buf->st_mode |= S_IREAD;
  65.     else if (fib->fib_Protection & FIBF_WRITE)
  66.         buf->st_mode |= S_IWRITE;
  67.     else if (fib->fib_Protection & FIBF_EXECUTE)
  68.         buf->st_mode |= S_IEXEC;
  69.     buf->st_size = fib->fib_Size;
  70.     FreeMem(fib,sizeof(struct FileInfoBlock));
  71.  
  72. /* what follows is a LATTICE call. Otherwise, time left blank, now: */
  73. #ifdef LATTICE
  74.     buf->st_atime =
  75.     buf->st_mtime =
  76.     buf->st_ctime = getft(name);
  77. #endif
  78.  
  79.     return 0;
  80. }
  81.  
  82.